<template>
  <div>
    <el-dialog
      title="新增酒店信息"
      :visible.sync="dialogVisible"
      width="650px"
      @close="close"
    >
      <el-form :model="ggData" :rules="rules" :inline="true" ref="userFrom">
        <div>
          <el-form-item label="管理员用户">
            <span style="margin-right: 10px"> {{ userInfo.nickname }} </span>
            <el-button type="primary" @click="adduseri">去绑定</el-button>
          </el-form-item>
        </div>
        <el-form-item label="酒店名称" prop="jdName">
          <el-input v-model="ggData.jdName"></el-input>
        </el-form-item>
        <el-form-item label="酒店电话" prop="jdPhone">
          <el-input type="number" v-model="ggData.jdPhone"></el-input>
        </el-form-item>
        <el-form-item label="酒店地址" prop="jdAddress">
          <el-input v-model="ggData.jdAddress"></el-input>
        </el-form-item>
        <!-- 回拨状态 -->
        <span style="margin-left:10px">
          <el-form-item label="自动回拨">
            <el-select
              v-model="ggData.isCallTime"
              placeholder="是否设置自动回拨时间"
              style="width: 200px;"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </span>
        <div v-if="ggData.isCallTime == 4" style="margin-left:9px;">
          <el-form-item label="开始时间">
            <el-date-picker
              value-format="yyyy-MM-dd HH:mm:ss"
              v-model="ggData.callTimeStart"
              type="datetime"
              placeholder="选择开始日期时间"
              style="width:200px"
            >
            </el-date-picker>
          </el-form-item>
          <span style="margin-left:8px">
            <el-form-item label="结束时间">
              <el-date-picker
                value-format="yyyy-MM-dd HH:mm:ss"
                v-model="ggData.callTimeEnd"
                type="datetime"
                placeholder="选择结束日期时间"
                style="width:200px"
              >
              </el-date-picker>
            </el-form-item>
          </span>
        </div>

        <div class="textarea">
          <el-form-item label="酒店描述" prop="jdDescribe">
            <el-input
              type="textarea"
              :rows="3"
              placeholder="请输入内容"
              v-model="ggData.jdDescribe"
            >
            </el-input>
            <!-- <el-input v-model="ggData.jijdDescribe"></el-input> -->
          </el-form-item>
        </div>
        <!-- 上传组件 -->
        <div class="upload">
          <el-form-item label="宣传图片:" prop="jdImg">
            <div class="acea-row">
              <div
                v-for="(item, index) in ggData.jdImg"
                :key="index"
                class="pictrue"
                draggable="true"
              >
                <img class="img" :src="item" />
                <i
                  v-if="!isDisabled"
                  class="el-icon-error btndel"
                  @click="handleRemove(index)"
                />
              </div>
              <div
                v-if="ggData.jdImg.length < 10 && !isDisabled"
                class="upLoadPicBox"
                @click="modalPicTap('2')"
              >
                <div class="upLoad">
                  <i class="el-icon-camera cameraIconfont" />
                </div>
              </div>
            </div>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
      <groggeryBoss
        ref="ggBoss"
        :userFrom="userFrom"
        :pagesize="pagesize"
        v-on:useruid="useruid"
        v-on:finduser="finduser"
      ></groggeryBoss>
    </el-dialog>
  </div>
</template>
<script>
import { addgroggeryinfoApi } from "@/api/groggery";
import { userListApi } from "@/api/groggery";
import groggeryBoss from "./groggeryBoss.vue";
export default {
  name: "grogGeryAdd",
  components: { groggeryBoss },
  data() {
    return {
      //回拨状态
      options: [
        {
          value: 0,
          label: "否"
        },
        {
          value: 1,
          label: "全天"
        },
        {
          value: 2,
          label: "白天"
        },
        {
          value: 3,
          label: "晚上"
        },
        {
          value: 4,
          label: "时间段"
        }
      ],
      // 新增
      ggData: {
        createTime: "", // 创建时间
        id: "", //酒店信息表id标识
        isDel: "", //是否删除
        isShow: "", //是否显示
        jdAddress: "", //酒店地址
        jdDescribe: "", //酒店描述
        jdImg: [], // 宣传图片
        jdName: "", //酒店名称
        jdPhone: "", //酒店电话
        sort: "", //排序
        status: "", //状态
        uid: "", //用户表d标识-这里表示这家酒店属于哪个用户
        updateTime: "", //更新时间
        callTimeEnd: "", // 自动回拨结束时间段
        callTimeStart: "", // 自动回拨开始时间段
        isCallTime: ""
      },
      //  用户员管理信息
      userFrom: [
        {
          page: 1,
          limit: 15
        }
      ],
      pagesize: {
        limit: "",
        page: "",
        total: "",
        totalPage: ""
      },
      // ggedit
      dialogVisible: false,
      dialogVisibletwo: false,
      // 地址
      dialogImageUrl: "",
      rules: {
        jdPhone: [
          {
            required: true,
            message: "请输入手机号",
            trigger: "blur"
          }
        ],
        jdName: [
          {
            required: true,
            message: "请输入酒店名称",
            trigger: "blur"
          }
        ],
        jdAddress: [
          {
            required: true,
            message: "请输入酒店地址",
            trigger: "blur"
          }
        ],
        jdDescribe: [
          {
            required: true,
            message: "请输入酒店描述",
            trigger: "blur"
          }
        ],
        jdImg: [
          {
            required: true,
            message: "请输入宣传图片",
            trigger: "blur"
          }
        ]
      },
      //存子
      userInfo: {
        uid: "",
        nickname: ""
      },
      isDisabled: this.$route.params.isDisabled === "1" ? true : false
    };
  },
  methods: {
    //上传组件
    handleRemove(i) {
      this.ggData.jdImg.splice(i, 1);
    },
    // 点击商品图
    modalPicTap(tit, num, i, status) {
      const _this = this;
      if (_this.isDisabled) return;
      this.$modalUpload(
        function(img) {
          if (tit === "1" && !num) {
            _this.ggData.jdImg = img[0].sattDir;
            _this.OneattrValue[0].image = img[0].sattDir;
          }
          if (tit === "2" && !num) {
            if (img.length > 10)
              return this.$message.warning("最多选择10张图片！");
            if (img.length + _this.ggData.jdImg.length > 10)
              return this.$message.warning("最多选择10张图片！");
            img.map(item => {
              _this.ggData.jdImg.push(item.sattDir);
            });
          }
        },
        tit,
        "content"
      );
    },
    // 关闭
    close() {
      this.userInfo.nickname = "";
    },
    // 新增提交
    submit() {
      this.$refs.userFrom.validate(async valid => {
        if (!valid) return;
        await addgroggeryinfoApi(this.ggData);
        this.dialogVisible = false;
        (this.ggData = {
          createTime: "", // 创建时间
          id: "", //酒店信息表id标识
          isDel: "", //是否删除
          isShow: "", //是否显示
          jdAddress: "", //酒店地址
          jdDescribe: "", //酒店描述
          jdImg: [], // 宣传图片
          jdName: "", //酒店名称
          jdPhone: "", //酒店电话
          sort: "", //排序
          status: "", //状态
          uid: "", //用户表d标识-这里表示这家酒店属于哪个用户
          updateTime: "", //更新时间
          callTimeEnd: "", // 自动回拨结束时间段
          callTimeStart: "", // 自动回拨开始时间段
          isCallTime: ""
        }),
          this.$message.success("添加成功");
        this.$parent.loadData();
        this.userInfo.nickname = "";
      });
    },
    // 选择管理员
    async adduseri() {
      let params = {
        page: 1,
        limit: 15
      };
      const res = await userListApi(params);
      this.userFrom = res.list;
      this.pagesize.limit = res.limit;
      this.pagesize.page = res.page;
      this.pagesize.total = res.total;
      this.pagesize.totalPage = res.totalPage;
      this.$refs.ggBoss.dialogTableVisible = true;
    },
    //子传过来的数据
    useruid(uid, nickname) {
      this.ggData.uid = uid;
      this.userInfo.nickname = nickname;
    },
    // 搜索
    finduser(userFrom) {
      this.userFrom = userFrom;
    }
  }
};
</script>

<style lang="scss" scoped>
.upload {
  display: flex;
  width: 800px;
  height: 100px;
  .pictrue {
    width: 60px;
    height: 60px;
    border: 1px dotted rgba(0, 0, 0, 0.1);
    margin-right: 10px;
    position: relative;
    cursor: pointer;
  }
  .img {
    width: 60px;
    height: 60px;
  }
  .btndel {
    position: absolute;
    z-index: 11111;
    width: 20px !important;
    height: 20px !important;
    left: 46px;
    top: -4px;
  }
}
.textarea {
  .el-form-item :last-child {
    width: 490px;
  }
}
</style>
